<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>批量添加到班级</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">

		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});

		function selectClassName(classId){
			$.ajax({
				type: "POST",
				url: "${ctx}/teach/teachStudent/findStudentByClassId",
				data: {
					classId:classId.options[classId.selectedIndex].value
				},
				success:function(json){
					$(".resetDuallist").empty();
					var list = json.dataObj;
					for(var t=0;t<list.StudentList.length;t++)
					{
						$("#duallist").append("<option value='"+ list.StudentList[t].id+"'>"+list.StudentList[t].name+"</option>");
					}
					$(".resetDuallist").bootstrapDualListbox('refresh');
				},
				error:function(){
					alertx("error");
				}
			});
		}

		function checkClassId() {
			var classId=document.getElementById("classId").value;
			var duallist=document.getElementById("duallist").value;
			if(classId==null || classId==""){
				window.alertx("请选择班级！");
				return false;
			}
			if(duallist==null || duallist==""){
				window.alertx("请选择学生！");
				return false;
			}
		}
	</script>

	<script type="text/javascript" src="${path}/js/common/jquery.min.js"></script>
	<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" type="text/css" media="all">
	<link rel="stylesheet" href="${path}/css/common/bootstrap-duallistbox.css" rel="stylesheet" type="text/css"/>
	<script type="text/javascript" src="${path}/js/common/jquery.bootstrap-duallistbox.js"></script>

	<style>
		.control-label{font-weight: normal;}
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/teach/teachStudent/">学生管理列表</a></li>
		<li class="active"><a href="${ctx}/teach/teachStudent/batchAddForm">批量添加到班级</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="teachStudent" action="${ctx}/teach/teachStudent/batchAdd" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">选择班级：</label>
			<div class="controls">
				<select id="classId" name="classId" class="required input-medium" onChange="selectClassName(this)">
					<option value="" selected>====请选择====</option>
					<c:forEach items="${allClassList}" var="allClass">
						<option value="${allClass.id}" >${allClass.className}</option>
					</c:forEach>
				</select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">选择学生：</label>
			<div class="controls">
				<div class="container"></div>
				<div class="col-lg-10 col-md-9 col-sm-9 col-xs-12">
					<select multiple="multiple" size="10" id="duallist" name="duallist" class="resetDuallist">
						<c:forEach var="allBatchAddStudent" items="${allBatchAddStudentList}">
							<option value="${allBatchAddStudent.id}">${allBatchAddStudent.name}</option>
						</c:forEach>
					</select>
				</div>
				<span class="help-inline" ><font color="red">*</font> </span>

			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="teach:teachStudent:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="添 加" onclick="return checkClassId()"/>&nbsp;</shiro:hasPermission>
			<%--<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>--%>
			<a class="btn" href="${ctx}/teach/teachStudent/">返回</a>
		</div>
	</form:form>


	<script>
		var demo1 = $('select[name="duallist"]').bootstrapDualListbox();
		$("#demoform").submit(function() {
			alert($('[name="duallist"]').val());
			return false;
		});
	</script>
</body>
</html>